<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/12/28
 * Time: 11:05
 */

namespace common\logics\taskorder;

use common\models\craftsman\TaskOrder;
use common\widgets\Tool;
use Yii;
use yii\base\BaseObject;

class TaskOrderLogic extends BaseObject implements ITaskOrder
{
	/** @var \common\sources\read\taskorder\TaskOrderAccess $RTaskOrderAccess ** */
	private $RTaskOrderAccess;
	/** @var \common\sources\write\taskorder\TaskOrderAccess $WTaskOrderAccess ** */
	private $WTaskOrderAccess;
	/** @var \common\sources\read\buyuser\BuyUserAccess $RBuyUserAccess * */
	private $RBuyUserAccess;
	/** @var \common\sources\read\taobao\TaoBaoAccess $RTaoBaoAccess */
	private $RTaoBaoAccess;
	/** @var \common\sources\read\taskshopimage\TaskShopImageAccess $RTaskShopImageAccess */
	private $RTaskShopImageAccess;
	/** @var \common\sources\write\taskshopimage\TaskShopImageAccess $WTaskShopImageAccess */
	private $WTaskShopImageAccess;
	/** @var \common\sources\read\valueservice\ValueServiceAccess $RValueServiceAccess * */
	private $RValueServiceAccess;
	/** @var \common\sources\read\praisekeywords\PraiseKeywordsAccess $RPraiseKeywordsAccess */
	private $RPraiseKeywordsAccess;
	/** @var \common\sources\write\praisekeywords\PraiseKeywordsAccess $WPraiseKeywordsAccess */
	private $WPraiseKeywordsAccess;
	/** @var \common\sources\read\taskorderlog\BuyTaskOrderLogAccess $RBuyTaskOrderLogAccess ** */
	private $RBuyTaskOrderLogAccess;
	/** @var \common\sources\read\buyprincipalcash\BuyPrincipalCashAccess $RBuyPrincipalCashAccess */
	private $RBuyPrincipalCashAccess;
	/** @var \common\sources\read\taskcommod\TaskCommodAccess $RTaskCommodAccess */
	private $RTaskCommodAccess;
	/** @var \common\sources\write\taskcommod\TaskCommodAccess  $WTaskCommodAccess **/
	private $WTaskCommodAccess;
	/** @var \common\sources\read\businessaccount\BusinessAccountAccess $RBusinessAccountAccess **/
	private $RBusinessAccountAccess;
	/** @var \common\sources\write\businessacount\BusinessAcountAccess  $WBusinessAccountAccess ***/
	private $WBusinessAcountAccess;
	/** @var \common\sources\write\businessdepositrecord\BusinessDepositRecordAccess $WBusinessDepositRecordAccess **/
	private $WBusinessDepositRecordAccess;
	/** @var \common\sources\write\businesspepperrecord\BusinessPepperRecordAccess $WBusinessPepperRecordAccess **/
	private $WBusinessPepperRecordAccess;
	/** @var \common\sources\read\taskcommodkeywords\TaskCommodKeywordAccess $RTaskCommodKeywordAccess **/
	private $RTaskCommodKeywordAccess;
	/** @var \common\sources\write\taskcommodkeywords\TaskCommodKeywordAccess $WTaskCommodKeywordAccess **/
	private $WTaskCommodKeywordAccess;
	/** @var \common\sources\write\taskorderlog\BuyTaskOrderLogAccess $WBuyTaskOrderLogAccess */
	private $WBuyTaskOrderLogAccess;

	public function init() {
		$this->RTaskOrderAccess             = Yii::$container->get("RTaskOrderAccess");
		$this->WTaskOrderAccess             = Yii::$container->get("WTaskOrderAccess");
		$this->RBuyUserAccess               = Yii::$container->get("RBuyUserAccess");
		$this->RTaoBaoAccess                = Yii::$container->get("RTaoBaoAccess");
		$this->RTaskShopImageAccess         = Yii::$container->get('RTaskShopImageAccess');
		$this->RValueServiceAccess          = Yii::$container->get('RValueServiceAccess');
		$this->RPraiseKeywordsAccess        = Yii::$container->get('RPraiseKeywordsAccess');
		$this->RBuyTaskOrderLogAccess       = Yii::$container->get("RBuyTaskOrderLogAccess");
		$this->RBuyPrincipalCashAccess      = Yii::$container->get("RBuyPrincipalCashAccess");
		$this->RTaskCommodAccess            = Yii::$container->get("RTaskCommodAccess");
		$this->WTaskCommodAccess            = Yii::$container->get("WTaskCommodAccess");
		$this->RBusinessAccountAccess       = Yii::$container->get("RBusinessAccountAccess");
		$this->WBusinessAcountAccess       = Yii::$container->get("WBusinessAcountAccess");
		$this->WBusinessDepositRecordAccess = Yii::$container->get("WBusinessDepositRecordAccess");
		$this->WBusinessPepperRecordAccess  = Yii::$container->get("WBusinessPepperRecordAccess");
		$this->RTaskCommodKeywordAccess     = Yii::$container->get("RTaskCommodKeywordAccess");
		$this->WTaskCommodKeywordAccess     = Yii::$container->get("WTaskCommodKeywordAccess");
		$this->WTaskShopImageAccess         = Yii::$container->get("WTaskShopImageAccess");
		$this->WPraiseKeywordsAccess        = Yii::$container->get("WPraiseKeywordsAccess");
		$this->WBuyTaskOrderLogAccess       = Yii::$container->get("WBuyTaskOrderLogAccess");

		parent::init(); // TODO: Change the autogenerated stub
	}

    public function PayOrderList($data) {
        $page_num = $data['page_num'];
        if(!$page_num)
        {
            $page_num = 1;
        }
        $count =  $this->RTaskOrderAccess->PayOrderList($data,true);
        $result = [];
        if($count<$data['limit'])
        {
            $data['page_num'] = 1;
        }
        if($count >0)
        {
            $result = $this->RTaskOrderAccess->PayOrderList($data);
            foreach ($result as &$value) {
                $value['create_time'] = date("Y-m-d H:i:s",$value['create_time']);
                $value['order_time'] = date("Y-m-d H:i:s",$value['order_time']);
                $value['taotal_price'] = number_format($value['price'] * $value['num'],2,".","");
            }
        }


        return Tool::returnJson([
            "list" => $result,
            "page_num" => $page_num,
            "count" => $count,
            "current_count" => count($result),
        ],200,"成功");
    }

    public function PassOrder($data) {
        if (empty($data['id'])) {
            return Tool::returnJson([],401,"订单id不能为空");
        }
        $result = $this->WTaskOrderAccess->PassOrder($data);
        if ($result) {
            return Tool::returnJson([],200,'通过成功');
        }
        return Tool::returnJson([],409,'通过失败');
    }

	public function OrderList($data) {
		$page_num = $data['page_num'];
        $count = $this->RTaskOrderAccess->getOrderListCount($data);
        if($count<$data['limit'])
        {
            $data['page_num'] =1;
        }
        $result = [];
        if($count> 0)
        {
            $result = $this->RTaskOrderAccess->getOrderLists($data);
            foreach ($result as &$value) {
                $value['bus_phone']   = isset($this->RBuyUserAccess->getBuyUserInfo($value['bus_id'])['phone']) ? $this->RBuyUserAccess->getBuyUserInfo($value['bus_id'])['phone'] : '';
                $value['order_time']  = empty($value['order_time']) ? '' : date("Y-m-d H:i:s", $value['order_time']);
                $value['create_time'] = empty($value['create_time']) ? '' : date("Y-m-d H:i:s", $value['create_time']);
                $value['print_time']  = empty($value['print_time']) ? '' : date("Y-m-d H:i:s", $value['print_time']);

                $task_types = Yii::$app->params['plat_task_type'][$value['plat_type']];
                $value['task_type_name'] = '';
                foreach ($task_types as $task_ty) {
                    if ($task_ty['task_type'] == $value['task_type']) {
                        $value['task_type_name'] = $task_ty['name'];
                    }
                }
            }
        }


		if ($result) {
			return Tool::returnJson([
				"list"     => $result,
				"page_num" => $page_num,
				"count"    => $count,
			], 200, "成功");
		}
		return Tool::returnJson([], 200, '成功');
	}

	/**
	 * TaskGiveUpNum 任务放弃数
	 * @param $data 参数
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/8
	 * @return false|string
	 */
	public function TaskGiveUpNum($data) {
		$list = $this->RTaskOrderAccess->TaskGiveUpNum($data);
		if ($list) {
			foreach ($list as &$value) {
				$info                    = $this->RTaskOrderAccess->getTaskOrderInfo($value['task_id']);
				$value['sub_task_id']    = $info['id'];
				$value['task_id']        = $info['task_id'];
				$value['task_commod_id'] = $info['task_commod_id'];
				$value['last_task_no']   = $info['task_order_num'];
				$value['last_task_time'] = date("Y-m-d H:i:s", $this->RTaskOrderAccess->GetTaskSubTime($value['task_id']));
			}
			unset($value);
			return Tool::returnJson($list, 200, '成功');
		}
		return Tool::returnJson([], 200, '成功');
	}

	public function TaskInfo($data) {
		if (empty($data['id'])) {
			return Tool::returnJson([], 401, "订单id不能为空");
		}
		$result = $this->RTaskOrderAccess->TaskInfo($data);
		if ($result) {
			if (!empty($result['task_shop_image_id']) && (2 == $result['task_type'])) {//图文任务
				//图文好评关键词
				$result['high_opinion_keywords'] = is_null($this->RTaskShopImageAccess->keyWorkersOfId($result['task_shop_image_id'])) ? '' : $this->RTaskShopImageAccess->keyWorkersOfId($result['task_shop_image_id']);
			} else {//非图文任务
				//先找到主任务task_commod_id
				$result['high_opinion_keywords'] = [];
				$valueService                    = $this->RValueServiceAccess->getList($result['task_commod_id']);
				if ($valueService) {
					$result['praise'] = $valueService['praise'];
					if (2 == $valueService['praise']) {
						$result['high_opinion_keywords'] = $valueService['praise_keys'];
					}
					if (3 == $valueService['praise']) {//自定义
						$result['high_opinion_keywords'] = is_null($this->RPraiseKeywordsAccess->keyWorkers($result['task_commod_id'])) ? '' : $this->RPraiseKeywordsAccess->keyWorkers($result['task_commod_id']);
						$result['praise_keywords']       = is_null($this->RPraiseKeywordsAccess->geIdInfo($result['praise_keywords_id'])) ? '' : $this->RPraiseKeywordsAccess->geIdInfo($result['praise_keywords_id']);
						unset($result['praise_keywords_id']);
					}
				}
			}
			$result['pay_url']        = isset($result['pay_url']) ? $result['pay_url'] : '';
			$result['pay_order_num']  = isset($result['pay_order_num']) ? $result['pay_order_num'] : '';
			$result['express_num']    = isset($result['express_num']) ? $result['express_num'] : '';
			$result['create_time']    = empty($result['create_time']) ? '' : date("Y-m-d H:i:s", $result['create_time']);
			$result['order_time']     = empty($result['order_time']) ? '' : date("Y-m-d H:i:s", $result['order_time']);
			$bus                      = $this->RBuyUserAccess->getBuyUserInfo($result['bus_id']);
			$result['business_phone'] = isset($bus['phone']) ? $bus['phone'] : '';
			$result['business_qq']    = isset($bus['qq']) ? $bus['qq'] : '';
			if (!empty($result['order_mark'])) {
				$result['order_mark'] = Yii::$app->params['questionOrder'][$result['order_mark']];
			} else {
				$result['order_mark'] = '';
			}

			$task_order_log = $this->RBuyTaskOrderLogAccess->getTaskOrderLog($data['id']);
			if (count($task_order_log) > 0) {
				foreach ($task_order_log as &$task_order) {
					$task_order['create_time'] = date('Y-m-d H:i:s', $task_order['create_time']);
				}
				unset($task_order);
			}
			$result['task_order_log'] = $task_order_log;

			//任务相关提现
			$cashList           = $this->RBuyPrincipalCashAccess->getUserIdInfo($result['buy_id']);
			$result['cashList'] = [];
			if ($cashList) {
				$status = Yii::$app->params['withdrawal_cash_status'];
				foreach ($cashList as $val) {
					if ($val['task_order_ids'] && in_array($result['id'], explode(',', $val['task_order_ids']))) {
						$val['status']        = isset($status[$val['status']]) ? $status[$val['status']] : $val['status'];
						$val['create_time']   = date('Y-m-d H:i:s', $val['create_time']);
						$val['update_time']   = !empty($val['update_time']) ? date('Y-m-d H:i:s', $val['create_time']) : '';
						$result['cashList'][] = $val;
					}
				}
			}
			return Tool::returnJson($result, 200, "成功");
		}
		return Tool::returnJson([], 409, '未查询到结果');
	}

    public function ModifyOrderPrice($data) {
        if (empty($data['id'])) {
            return Tool::returnJson([],401,"订单id不能为空");
        }
        if (empty($data['price'])) {
            return Tool::returnJson([],401,"价格不能为空");
        }
        $result = $this->WTaskOrderAccess->ModifyOrderPrice($data);
        if ($result) {
            return Tool::returnJson($result,200,"成功");
        }
        return Tool::returnJson([],409,'修改失败');
    }

    public function ModifyOrderNo($data) {
        if (empty($data['id'])) {
            return Tool::returnJson([],401,"订单id不能为空");
        }
        if (empty($data['orderNo'])) {
            return Tool::returnJson([],401,"订单号不能为空");
        }
        $result = $this->WTaskOrderAccess->ModifyOrderNo($data);
        if ($result) {
            return Tool::returnJson($result,200,"成功");
        }
        return Tool::returnJson([],409,'修改失败');
    }

    public function EditOrder($data) {
        if(empty($data['id'])){
            return Tool::returnJson([],401,"订单id不能为空");
        }
        if(empty($data['actual_price'])){
            return Tool::returnJson([],401,"金额不能为空");
        }
        if(empty($data['pro_name'])){
            return Tool::returnJson([],401,"shen不能为空");
        }
        if(empty($data['city_name'])){
            return Tool::returnJson([],401,"市不能为空");
        }
        if(empty($data['area_name'])){
            return Tool::returnJson([],401,"区不能为空");
        }
        if(empty($data['addr'])){
            return Tool::returnJson([],401,"详细地址不能为空");
        }
        if(empty($data['receive_name'])){
            return Tool::returnJson([],401,"收件人不能为空");
        }
        if(empty($data['receive_phone'])){
            return Tool::returnJson([],401,"收件人手机不能为空");
        }
        if(empty($data['pay_url'])){
            return Tool::returnJson([],401,"支付截图不能为空");
        }
        if(empty($data['addr_url'])){
            return Tool::returnJson([],401,"地址截图不能为空");
        }
        $result = $this->WTaskOrderAccess->EditOrder($data);
        if ($result) {
            return Tool::returnJson($result,200,"成功");
        }
        return Tool::returnJson([],409,'修改失败');
    }

    public function ExpessPrintList($data) {

        $count = $this->RTaskOrderAccess->ExpessPrintList($data,true);
        if($count<$data['page_num'])
        {
            $data['page_num'] =1;
        }
        $list = [];
        if($count >0)
        {
            $list = $this->RTaskOrderAccess->ExpessPrintList($data);
            foreach ($list as &$value) {
                $value['order_time'] = empty($value['order_time']) ? '' : date("Y-m-d H:i:s",$value['order_time']);
            }
        }

        return Tool::returnJson([
            'list' => $list,
            'page_num' => $data['page_num'],
            'count' => $count
        ],200,'成功');
    }

    public function QuestionReason() {
        $reason = Yii::$app->params['questionOrder'];
        return Tool::returnJson($reason,200,'成功');
    }

    public function ModifyOrderMark($data) {
        if(empty($data['id'])){
            return Tool::returnJson([],401,"订单id不能为空");
        }
        if(empty($data['mark_id'])){
            return Tool::returnJson([],401,"问题原因不能为空");
        }
        if(empty($data['reason'])){
            return Tool::returnJson([],401,"备注不能为空");
        }
        $result = $this->WTaskOrderAccess->ModifyOrderMark($data);
        if ($result) {
            return Tool::returnJson([],200,"成功");
        }
        return Tool::returnJson([],409,"失败");
    }

	/**
	 * cancelOrder 取消订单逻辑
	 * @param $data
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/9
	 * @return false|string
	 * @throws \yii\db\Exception
	 */
	public function cancelOrder($data) {
		if (empty($data['id'])) {
			return Tool::returnJson([], 401, "子订单id不能为空");
		}
		if (empty($data['operator'])) {
			return Tool::returnJson([], 408, "操作人不能为空");
		}
		$task_order = $this->RTaskOrderAccess->getTaskOrderById($data['id']);
		if (empty($task_order)) {
			return Tool::returnJson([], 407, "子任务单号不存在");
		}
//		if ($task_order['order_status'] != 1) {
//			return Tool::returnJson([], 408, "该订单不能取消");
//		}
        if (in_array($task_order['order_status'],[8,10,11,12,13])) {
            return Tool::returnJson([], 408, "该订单不能取消");
        }
		//查询主任务
		$taskCommod = $this->RTaskCommodAccess->getTaskDetail($task_order['task_commod_id']);
		if (empty($taskCommod)) {
			return Tool::returnJson([], 410, "主任务不存在,暂时不能取消");
		}
		//放弃任务次数限制
		/*$give_up_count = $this->RTaskOrderAccess->getBuyTaskOrderCount($data['buy_id'], 10);
		if ($give_up_count > 2) {
			return Tool::returnJson([], 411, "你放弃任务已经超过3次");
		}*/

		// 开启事务 处理逻辑
		$transaction = Yii::$app->db->beginTransaction();
		try {
            $res = false;
		    if($task_order['order_status'] == 1)
		    {
                //修改子任务状态
                $res = $this->WTaskOrderAccess->modifyTask(["order_status" => 10, "id" => $data['id']]);
            }else if(($task_order['order_status'] >1 || $task_order['order_status'] <10)&& $task_order['order_status'] !=8 )
            {
                $res = $this->WTaskOrderAccess->modifyTask(["order_status" => 11, "id" => $data['id']]);
            }
			if ($res) {
				if ($taskCommod['task_status'] == 5) { //返回商家 任务个数
					//增值服务
					$value_service = $this->RValueServiceAccess->getList($taskCommod['id']);
					if (empty($value_service)) {
						$transaction->rollBack();
						return Tool::returnJson([], 412, "商家增值服务异常");
					}
					//修改主任务信息
					$res_task = $this->WTaskCommodAccess->modifyTaskCommod(["task_answer" => $taskCommod['task_answer'] - 1, "surplus_task_num" => $taskCommod['surplus_task_num'] + 1, "id" => $task_order['task_commod_id']]);
					if (!$res_task) {
						$transaction->rollBack();
						return Tool::returnJson([], 413, "取消任务失败");
					}

					//商家信息
					$businessAccount = $this->RBusinessAccountAccess->getBusinessAccount($taskCommod['bus_id']);
					if (empty($businessAccount)) {
						$transaction->rollBack();
						return Tool::returnJson([], 415, "商家账号异常");
					}

					//修改账号佣金
					$service_pepper   = number_format($value_service['return_type_pepper'] + $value_service['chat_pepper'] + $value_service['extend_pepper'] + $value_service['sex_pepper']
						+ $value_service['praise_pepper'] + $value_service['reword_commise'] + $value_service['service_pepper'] + $taskCommod['item_commisse'], 2, ".", "");
					$freezing_deposit = number_format($businessAccount['freezing_deposit'] - $taskCommod['price'] * $taskCommod['num'] * 1.05 - $taskCommod['freight_deposit'], 2, '.', '');     //冻结押金
					$ava_deposit      = number_format($businessAccount['ava_deposit'] + $taskCommod['price'] * $taskCommod['num'] * 1.05 + $taskCommod['freight_deposit'], 2, '.', '');               //可用押金
					$ava_pepper       = number_format($businessAccount['ava_pepper'] + $service_pepper, 2, '.', '');                                                                             //可用花椒
					$freezing_golds   = number_format($businessAccount['freezing_golds'] - $service_pepper, 2, '.', '');                                                                     //冻结花椒
					//修改账号余额
					$accout_arr  = [
					    "total_deposit" => $businessAccount['total_deposit'],
						"ava_deposit"      => $ava_deposit,
						"ava_pepper"       => $ava_pepper,
						"freezing_deposit" => $freezing_deposit,
						"freezing_golds"   => $freezing_golds,
						'bus_id'           => $task_order['bus_id'],
					];
					$account_res = $this->WBusinessAcountAccess->modifyAcount($accout_arr);
					if (!$account_res) {
						$transaction->rollBack();
						return Tool::returnJson([], 416, "取消任务回退商家资金失败");
					}

					//退押金记录
					$deposit_arr  = [
						"bus_id"         => $task_order['bus_id'],
						"task_commod_id" => $taskCommod['id'],
						"task_id"        => $taskCommod['task_id'],
						'task_order_id'  => $task_order['id'],
						'task_order_num' => $task_order['task_order_num'],
						"expend"         => 0,
						"type"           => 3,
						"income"         => number_format($taskCommod['price'] * $taskCommod['num'] * 1.05 + $taskCommod['freight_deposit'], 2, ".", ""),
						"balance"        => $ava_deposit,
                        "freeze_change" => -number_format($taskCommod['price'] * $taskCommod['num'] * 1.05 + $taskCommod['freight_deposit'],2,".",""),
                        "freeze_balance" => $freezing_deposit,
						"remark"         => "取消任务退还商家押金",
						"operatorId"     => $data['operator'],
					];
					$deposite_res = $this->WBusinessDepositRecordAccess->addDepositRecord($deposit_arr);
					if (!$deposite_res) {
						$transaction->rollBack();
						return Tool::returnJson([], 417, "取消任务退还押金失败");
					}

					//退花椒
					$bus_pepper_arr = [
						"bus_id"         => $task_order['bus_id'],
						"task_commod_id" => $task_order['task_commod_id'],
						"task_id"        => $taskCommod['task_id'],
						'task_order_id'  => $task_order['id'],
						'task_order_num' => $task_order['task_order_num'],
						"expend"         => 0,
						"type"           => 3,
						"income"         => $service_pepper,
						"balance"        => $ava_pepper,
                        "freeze_change" => -$service_pepper,
                        "freeze_balance" => $freezing_golds,
						"remark"         => "取消任务退还花椒",
						"operatorId"     => $data['operator']
					];
					$bus_pepper_res = $this->WBusinessPepperRecordAccess->addPeppersRecord($bus_pepper_arr);
					if (!$bus_pepper_res) {
						$transaction->rollBack();
						return Tool::returnJson([], 418, "取消任务退还花椒失败");
					}

				} else if ($taskCommod['task_status'] == 4) { //4.进行中
					$res_task = $this->WTaskCommodAccess->modifyTaskCommod(["task_answer" => $taskCommod['task_answer'] - 1, "surplus_task_num" => $taskCommod['surplus_task_num'] + 1, "id" => $task_order['task_commod_id']]);
					if (!$res_task) {
						$transaction->rollBack();
						return Tool::returnJson([], 419, "取消任务失败");
					}
					//回退已经选择得关键字
					if (($task_order['plat_type'] == 1 || $task_order['plat_type'] == 2) && ($task_order['task_type'] == 1 || $task_order['task_type'] == 2)) {
						if (!empty($task_order['task_commod_keyword_id'])) {
							//关键字查询
							$task_commod_keyword = $this->RTaskCommodKeywordAccess->getTaskCommodKeywordById($task_order['task_commod_keyword_id']);
							if (empty($task_commod_keyword)) {
								$transaction->rollBack();
								return Tool::returnJson([], 420, "取消任务回退关键字异常");
							}
							//回退个数
							$res_task_commod_keyword = $this->WTaskCommodKeywordAccess->modifyTaskCommodKeyword(["use_num" => $task_commod_keyword['use_num'] - 1, "task_commod_keyword_id" => $task_commod_keyword['id']]);
							if (!$res_task_commod_keyword) {
								$transaction->rollBack();
								return Tool::returnJson([], 421, "取消任务回退关键字失败");
							}
						}
					}
					//判断是否是取消图文任务
					if (($task_order['plat_type'] == 1 || $task_order['plat_type'] == 2) && $task_order['task_type'] == 2) {
						if (!empty($task_order['task_shop_image_id'])) {
							$task_shop_image = $this->RTaskShopImageAccess->keyWorkersOfId($task_order['task_shop_image_id']);
							if (empty($task_shop_image)) {
								$transaction->rollBack();
								return Tool::returnJson([], 422, "取消任务回退图文任务异常");
							}
							$res_task_shop_image = $this->WTaskShopImageAccess->modifyTaskShop(['id' => $task_order['task_shop_image_id'], 'is_effect' => 0]);
							if (!$res_task_shop_image) {
								$transaction->rollBack();
								return Tool::returnJson([], 423, "取消图文任务回退失败");
							}
						}
					}
					if (($task_order['plat_type'] == 1 || $task_order['plat_type'] == 2) && ($task_order['task_type'] == 1 || $task_order['task_type'] == 4)) {
						//获取好评关键字id
						if (!empty($task_order['praise_keywords_id'])) {
							$praise_keyword = $this->RPraiseKeywordsAccess->geIdInfo($task_order['praise_keywords_id']);
							if (empty($praise_keyword)) {
								$transaction->rollBack();
								return Tool::returnJson([], 425, "取消任务回退增值服务好评关键字异常");
							}
							$res_praise_keyword = $this->WPraiseKeywordsAccess->modifyPraisekeywords(['id' => $task_order['praise_keywords_id'], "is_user" => 1]);
							if (!$res_praise_keyword) {
								$transaction->rollBack();
								return Tool::returnJson([], 426, "取消增值服务好评关键字失败");
							}
						}
					}

				}
				//添加接任务日志
				$task_order_arr = [
					"buy_id"        => $task_order['buy_id'],
					"task_status"   => 10,
					"status_remark" => "取消任务",
					"remark"        => $data['remark'],
					"task_order_id" => $task_order['id'],
					"operator"      => $data['operator'],
				];
				$task_order_res = $this->WBuyTaskOrderLogAccess->addTaskOrderLog($task_order_arr);
				if (!$task_order_res) {
					$transaction->rollBack();
					return Tool::returnJson([], 427, "添加操作日志失败");
				}
				$transaction->commit();
				return Tool::returnJson([], 200, "成功");
			}
			$transaction->rollBack();
			return Tool::returnJson([], 428, "取消任务失败");
		} catch (\Exception $e) {
			$transaction->rollBack();
			return Tool::returnJson([], 500, "操作异常，取消失败" . $e->getMessage());
		}
		return Tool::returnJson([], 409, "取消失败");
	}
}